package org.ljy.forum6.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.ljy.forum6.common.AppResult;
import org.ljy.forum6.model.Board;
import org.ljy.forum6.services.impl.BoardServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Api(tags = "版块接口")
@Slf4j
@RestController
@RequestMapping("/board")
public class BoradController {

    @Value("${bit-forum.index.board-num:9}")
    private Integer indexBoardNum;

    @Resource
    private BoardServiceImpl boardService;


    /**
     * 获取所有的版块信息
     * @return 返回所有版块
     */
    @ApiOperation("获取版块")
    @GetMapping("/topList")
    public AppResult<List<Board>> topList() {
        //1.参数验证

        //2.调用service层
        List<Board> boards = boardService.selectByNum(indexBoardNum);
        if(boards==null) {
            boards = new ArrayList<Board>();
        }
        //3.返回结果
        return AppResult.success(boards);
    }
    @ApiOperation("获取版块详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam("版块id")
                                         @RequestParam("id")
                                         @NonNull Long id) {
        //1.调用service
        Board board = boardService.selectById(id);
        return AppResult.success(board);
    }


}
